package com.armani.service.impl;

import com.armani.mapper.OrderDetailMapper;
import com.armani.mapper.OrderMapper;
import com.armani.mapper.SnapshotMapper;
import com.armani.model.OrderModel;
import com.armani.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ProjectName: armani
 * @Package: com.armani.service.impl
 * @ClassName: OrderServiceImpl
 * @Description: 订单接口实现类
 * @Author: lenovo
 * @Date: 2021/11/28 23:05
 * @Version: 1.0
 **/
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Autowired
    private SnapshotMapper snapshotMapper;

    /**
     * 查询订单列表展示
     *
     * @param params 参数（筛选条件）
     * @return 订单列表展示集合
     */
    @Override
    public List<OrderModel> detail(Map<String, Object> params) {
        List<OrderModel> orderList = orderMapper.search(params);
        for (OrderModel order : orderList) {
            order.setItemList(orderDetailMapper.selectByOrderNo(order.getOrderNum()));
            order.setAddress(snapshotMapper.addressByOrderNo(order.getOrderNum()));
        }
        return orderList;
    }
    /**
     * 获取订单列表数量
     *
     * @param params 参数（筛选条件）
     * @return 数量
     */
    @Override
    public Integer count(Map<String, Object> params) {
        return orderMapper.count(params);
    }



    /**
     * 添加商品信息到快照
     *
     * @param itemName
     * @param ItemParam
     * @param price
     * @param num
     * @param orderTime
     * @param totalPrice
     * @param orderId
     * @param shopUser
     * @param phone
     * @param province
     * @param city
     * @param district
     * @param detail
     * @param note
     * @return
     * @throws Exception
     */
    @Override
    public Integer insertSnapshot(String itemName, String ItemParam, BigDecimal price, Integer num, Date orderTime, BigDecimal totalPrice, Integer orderId, String shopUser, String phone, String province, String city, String district, String detail, String note) throws Exception {
        return null;
    }

    /**
     * 删除订单（逻辑删除）
     *
     * @return
     * @throws Exception
     */
    @Override
    public Integer del(Integer userId) throws Exception {
        return orderMapper.del(userId);
    }
}
